package com.hujf.flink.ch05;

import org.apache.flink.streaming.api.functions.source.SourceFunction;

import java.util.Calendar;
import java.util.Random;

/**
 * @Author hujf
 * @Date 2022/3/24 17:18
 * @Description TODO
 */
public class ClickSource implements SourceFunction<Event> {

    private Boolean running =true;
    @Override
    public void run(SourceContext<Event> ctx) throws Exception {
        Random random = new Random();
        String []users = {"mary","jack","Bob","Alice"};
        String []urls = {"/home","/baidu","/fac","/uid"};
        //循环生成数据
        while (running){
            String user = users[random.nextInt(users.length)];
            String url = urls[random.nextInt(urls.length)];
            Long time  = Calendar.getInstance().getTimeInMillis();
            ctx.collect(new Event(user,url,time));
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {

    }
}
